<?php
/**
 * @package orinoco.framework
 * @subpackage framework
 * @author Ryan Yonzon <rawswift@gmail.com>
 * @copyright Copyright 2008 Ryan Yonzon 
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 */

require('helper.core.php');

/**
 * helper methods that are available in view/template
 */
class coreView extends coreHelper {

	/**
	 * render controllers/methods view template
	 * this method must be called inside the layout template/wrapper
	 * to pull/render the methods view
	 * 
	 * @return bool true is successful, otherwise false
	 */  
	public function render_content() {
		// check if view template is set explicitly
		if(isset($this->__view)) {
			$_content_view = $this->__view;
		} else {
			// use associated view template 
			$_content_view = APPLICATION_DIR . $this->_application . '/' . CONTENT_DIR . $this->_controller . '/' . $this->_method . VIEW_FILE_SUFFIX . VIEW_FILE_EXTENSION;
		}
		
			// check if methods view file exists
			if(!file_exists($_content_view)) {
				// NO verbose
				return false;
			}
			
			// include/use view template
			require($_content_view);
			return true;				
	}
	
	/**
	 * render partial template
	 *
	 * @param string $_partial_name partial template name
	 * @return bool true is successful, otherwise false
	 */
	public function render_partial($_partial_name) {
		$_partial_path = APPLICATION_DIR . $this->_application . '/' . PARTIAL_DIR . $_partial_name . PARTIAL_FILE_SUFFIX . PARTIAL_FILE_EXTENSION;
			
			// check if partial template exists
			if (!file_exists($_partial_path)) {
				throw new Exception('Partial template "' . $_partial_path . '" does not exists.');
				return false;
			}
			
				require($_partial_path);
				return true;
	}

	/**
	 * get default layout/wrapper template
	 *
	 * @return bool|string default layout's path
	 */
	protected function getDefaultLayout() {
		$_layout_wrapper = APPLICATION_DIR . $this->_application . '/' . LAYOUT_DIR . DEFAULT_LAYOUT . LAYOUT_FILE_SUFFIX . LAYOUT_FILE_EXTENSION;
		if(file_exists($_layout_wrapper)) { 
			return APPLICATION_DIR . $this->_application . '/' . LAYOUT_DIR . DEFAULT_LAYOUT . LAYOUT_FILE_SUFFIX . LAYOUT_FILE_EXTENSION;
		}
		return false;
	}
	
} // end class

// -EOF-